package com.cn.crmsystem.controller.customerController;

import com.cn.crmsystem.pojo.*;
import com.cn.crmsystem.service.customerService.ContactsService;
import io.swagger.annotations.*;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@Api(value ="联系人数据test",tags ="联系人数据接口API")
public class ContactsController {
    @Autowired
    private ContactsService contactsService;

    @ResponseBody
    @RequestMapping(value = "/insertContacts",method = RequestMethod.POST)
    @ApiOperation(value ="新增联系人数据接口",notes = "填写联系人基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "Contacts",value = "联系人基本信息",required = false)
    public ResultJson insertContacts(@RequestBody Contacts contacts){
        System.out.println(contacts.getName()+"****");
        //获取当前登录用户
         Login login = (Login) SecurityUtils.getSubject().getPrincipal();
//        Login login =new Login();
//        login.setUser_id(1);
        System.out.println(login.getUser_id());
        return  contactsService.insertContacts(contacts,login);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteContacts",method = RequestMethod.POST)
    @ApiOperation(value ="删除联系人数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "id",value = "联系人数据id",required = false,dataType = "Integer",paramType = "query")
    public ResultJson deleteContacts(Integer id){
        System.out.println(id);
        return contactsService.deleteContacts(id);
    }

    @ResponseBody
    @RequestMapping(value = "/updateContacts",method = RequestMethod.POST)
    @ApiOperation(value ="修改联系人数据接口",notes = "填写修改后联系人基本数据",httpMethod = "POST",response = ResultJson.class)
    @ApiParam(name = "contacts",value = "修改后联系人基本信息",required = false)
    public ResultJson updateContacts(@RequestBody Contacts contacts) {
        System.out.println(contacts.getName() + "****");
        //User user = (User) SecurityUtils.getSubject().getPrincipal();
        return contactsService.updateContacts(contacts);
    }

    @ResponseBody
    @RequestMapping(value = "/selectContacts",method = RequestMethod.POST)
    @ApiOperation(value ="条件查询联系人数据接口",notes = "填写筛选条件数据",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "name",value = "联系人名字",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "customer_name",value = "线索（客户）名称",paramType = "query",dataType = "String",required = false),
            @ApiImplicitParam(name = "user_name",value = "负责人姓名",paramType = "query",dataType = "Integer",required = false),
            @ApiImplicitParam(name = "create_name",value = "创建人姓名",paramType = "query",dataType = "Integer",required = false)
    })
    public ResultJson<List> selectContacts(@RequestBody @RequestParam @ApiParam(required = false) Map<String,Object> map) {
        System.out.println(map.get("create_id"));
        return contactsService.selectContacts(map);
    }

    @ResponseBody
    @RequestMapping(value = "/deleteAllContacts",method = RequestMethod.POST)
    @ApiOperation(value ="批量删除联系人数据接口",notes = "传入要删除的数据id",httpMethod = "POST",response = ResultJson.class)
    @ApiImplicitParam(name = "ids",value = "线索id",paramType = "query",dataType = "String",required = false)
    public ResultJson deleteAllContacts(Integer[] ids){
        System.out.println(ids.length);
        return contactsService.deleteAllContacts(ids);

    }
}
